Option Explicit

'################################################################
' Descriptr
' 列类型枚举--数据处理器
'################################################################

Implements IDFDataTypeHandler

'################################################################
' Field
'################################################################
' 类型
Private fieldDataType As DF_DataType

'################################################################
' Constructor
'################################################################
Private Sub Class_Initialize()
    fieldDataType = DF_DataType.DF_TIME
End Sub

Private Sub Class_Terminate()
End Sub

'################################################################
' Property
'################################################################
'----------------------------
' 处理器处理的类型
'----------------------------
' 获取当前处理器处理的类型
Public Property Get IDFDataTypeHandler_DataType() As DF_DataType
    IDFDataTypeHandler_DataType = fieldDataType
End Property


'----------------------------
' 是否支持计算方法
'----------------------------
' 是否支持加法运算
Public Property Get IDFDataTypeHandler_SupportAdd() As Boolean
    IDFDataTypeHandler_SupportAdd = True
End Property

' 是否支持减法运算
Public Property Get IDFDataTypeHandler_SupportSubtract() As Boolean
    IDFDataTypeHandler_SupportSubtract = True
End Property

' 是否支持乘法运算
Public Property Get IDFDataTypeHandler_SupportMultiply() As Boolean
    IDFDataTypeHandler_SupportMultiply = False
End Property

' 是否支持除法运算
Public Property Get IDFDataTypeHandler_SupportDivide() As Boolean
    IDFDataTypeHandler_SupportDivide = False
End Property

'----------------------------
' 是否支持聚合运算
'----------------------------
' 是否支持最大值运算
Public Property Get IDFDataTypeHandler_SupportMax() As Boolean
    IDFDataTypeHandler_SupportMax = True
End Property

' 是否支持最小值运算
Public Property Get IDFDataTypeHandler_SupportMin() As Boolean
    IDFDataTypeHandler_SupportMin = True
End Property

'################################################################
' Function
'################################################################
'----------------------------
' 数据初始化
'----------------------------
' 将输入数据进行初始化
'
' @param origin 原始输入数据
' @return 初始化后的数据
Public Function IDFDataTypeHandler_normalize(ByRef origin As Variant) As Variant
    If IsEmpty(origin) = True Then
        IDFDataTypeHandler_normalize = Empty
    Else
        Dim tName As String
        tName = TypeName(origin)
        If tName = "Date" Then
            ' 如果数据本身就是 date 类型，则直接返回不做任何处理
            IDFDataTypeHandler_normalize = origin
        ElseIf tName <> "String" Then
            ' 如果数据不是 Date 类型，也不是可处理的字符串类型，则忽略数据内容，直接使用 Empty
            IDFDataTypeHandler_normalize = Empty
        Else
On Error Goto catch:
            IDFDataTypeHandler_normalize = UtilsDate.strToTime(origin & "")
            Exit Function
catch:
            ' 发生异常时，统一返回 Empty，不抛出异常
            Err.Clear
            IDFDataTypeHandler_normalize = Empty
        End If
    End If
End Function

'----------------------------
' 计算方法
'----------------------------

' 将运算数据转换成当前类型的标准计算类型数据
' 如果需要终止计算，应该返回 Empty
'
' 如果无法转换成可计算的整数，则默认返回 Empty，不抛出异常 !!!!
'
' @param v 原始计算数据
' @return 当前类型的标准计算类型数据
Public Function IDFDataTypeHandler_normalizeComputeData(ByRef v As Variant) As Variant
On Error Goto catch:
    IDFDataTypeHandler_normalizeComputeData = Int(v)
catch:
    ' 如果无法转换成可计算的整数，则默认返回 Empty，不抛出异常 !!!!
    IDFDataTypeHandler_normalizeComputeData = Empty
End Function

' 对数据进行加法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_add(ByRef origin As Variant, ByRef v As Variant) As Variant
    If IsEmpty(origin) Then
        ' 如果原始时间是 Empty，则不做计算
        IDFDataTypeHandler_add = Empty
    Else
        IDFDataTypeHandler_add = DateAdd("s", v, origin)
    End If
End Function

' 对数据进行减法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_subtract(ByRef origin As Variant, ByRef v As Variant) As Variant
    If IsEmpty(origin) Then
        ' 如果原始日期是 Empty，则不做计算
        IDFDataTypeHandler_subtract = Empty
    Else
        IDFDataTypeHandler_subtract = DateAdd("s", -v, origin)
    End If
End Function

' 对数据进行乘法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_multiply(ByRef origin As Variant, ByRef v As Variant) As Variant
    IDFDataTypeHandler_multiply = origin
End Function

' 对数据进行除法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_divide(ByRef origin As Variant, ByRef v As Variant) As Variant
    IDFDataTypeHandler_divide = origin
End Function


' ==============
' 数组引用计算，并直接修改数组的值
' ==============
' 对数据进行加法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_addForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 1. 将运算数据转换成标准计算类型数据
    Dim computeData As Variant
    computeData = normalizeComputeData(v)

    ' 2. 如果计算数据是 Empty，则不做计算
    If IsEmpty(computeData) Then
        Exit Sub
    End If

    ' 3. 对所有数据进行计算
    Dim i As Long
    For i = LBound(origin) To UBound(origin)
        If Not IsEmpty(origin(i)) Then
            origin(i) = DateAdd("s", computeData, origin(i))
        End If
    Next
End Sub

' 对数据进行减法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_subtractForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 1. 将运算数据转换成标准计算类型数据
    Dim computeData As Variant
    computeData = normalizeComputeData(v)

    ' 2. 如果计算数据是 Empty，则不做计算
    If IsEmpty(computeData) Then
        Exit Sub
    End If

    ' 3. 对所有数据进行计算
    Dim i As Long
    For i = LBound(origin) To UBound(origin)
        If Not IsEmpty(origin(i)) Then
            origin(i) = DateAdd("s", -computeData, origin(i))
        End If
    Next
End Sub

' 对数据进行乘法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_multiplyForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 不支持
End Sub

' 对数据进行除法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_divideForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 不支持
End Sub


'----------------------------
' 和其他 Series 做计算方法
'----------------------------

' 对数据进行加法运算
' 如果 src 不支持和 desc 的类型做计算，将不会执行计算
' 如果 src 的长度比 desc 大，则多余的数据不会进行计算
'
' 支持的 desc 类型: DF_INT, DF_DECIMAL, DF_BOOLEAN(按照0,1计算)
' 如果 src 中的某个值是 Empty，则不做计算
'
' @param src 原始数据（如果类型和当前处理器的类型不同，将不会计算）
' @param desc 需要被合并计算的数据
Public Sub IDFDataTypeHandler_mergeAdd(ByRef src As IDFSeries, ByRef desc As IDFSeries)
    ' 1. 如果 src 的类型和当前处理器的类型不同，将不会计算
    If src.DataType <> fieldDataType Then
        Exit Sub
    End If

    ' 2. 检查 desc 的类型
    If desc.DataType <> DF_DataType.DF_INT And _
        desc.DataType <> DF_DataType.DF_DECIMAL And _
        desc.DataType <> DF_DataType.DF_BOOLEAN _
        Then
        Exit Sub
    End If

    ' 3. 计算需要处理的数据量
    '    以 src, desc 中数据量小的那个为标准做计算
    Dim maxIndex As Long
    If src.Size > desc.Size Then
        maxIndex = desc.Size - 1
    Else
        maxIndex = src.Size - 1
    End If

    ' 4. 开始计算
    Dim i As Long
    Dim left As Variant
    Dim right As Variant
    If desc.DataType <> DF_DataType.DF_INT Or desc.DataType = DF_DataType.DF_DECIMAL Then
        For i = 0 To maxIndex
            right = desc.unsafeGetData(i)

            ' 如果右值是 Empty，则不进行计算
            If IsEmpty(right) Then
                Goto continueInt
            End If

            ' 如果左值是 Empty，则不进行计算
            left = src.unsafeGetData(i)
            If IsEmpty(left) Then
                Goto continueInt
            End If

            src.unsafeSetData i, DateAdd("s", Int(right), left)
continueInt:
        Next
    ElseIf desc.DataType = DF_DataType.DF_BOOLEAN Then
        For i = 0 To maxIndex
            right = desc.unsafeGetData(i)

            If IsEmpty(right) Then
                ' 如果右值是 Empty，则不进行计算
                Goto continueBoolean
            ElseIf right = False Then
                ' 如果右值是 False 时 + 0，即不做处理
                Goto continueBoolean
            End If

            ' 如果左值是 Empty，则不进行计算
            left = src.unsafeGetData(i)
            If IsEmpty(left) Then
                Goto continueInt
            End If

            src.unsafeSetData i, DateAdd("s", 1, left)
continueBoolean:
        Next
    End If
End Sub

' 对数据进行减法运算
' 如果 src 不支持和 desc 的类型做计算，将不会执行计算
' 如果 src 的长度比 desc 大，则多余的数据不会进行计算
'
' 支持的 desc 类型: DF_INT, DF_DECIMAL, DF_BOOLEAN(按照0,1计算)
' 如果 src 中的某个值是 Empty，但是 desc 中也是 Empty，则不会进行计算，继续保持 Empty
'
' @param src 原始数据（如果类型和当前处理器的类型不同，将不会计算）
' @param desc 需要被合并计算的数据
Public Sub IDFDataTypeHandler_mergeSubtract(ByRef src As IDFSeries, ByRef desc As IDFSeries)
    ' 1. 如果 src 的类型和当前处理器的类型不同，将不会计算
    If src.DataType <> fieldDataType Then
        Exit Sub
    End If

    ' 2. 检查 desc 的类型
    If desc.DataType <> DF_DataType.DF_INT And _
        desc.DataType <> DF_DataType.DF_DECIMAL And _
        desc.DataType <> DF_DataType.DF_BOOLEAN _
        Then
        Exit Sub
    End If

    ' 3. 计算需要处理的数据量
    '    以 src, desc 中数据量小的那个为标准做计算
    Dim maxIndex As Long
    If src.Size > desc.Size Then
        maxIndex = desc.Size - 1
    Else
        maxIndex = src.Size - 1
    End If

    ' 4. 开始计算
    Dim i As Long
    Dim left As Variant
    Dim right As Variant
    If desc.DataType <> DF_DataType.DF_INT Or desc.DataType = DF_DataType.DF_DECIMAL Then
        For i = 0 To maxIndex
            right = desc.unsafeGetData(i)

            ' 如果右值是 Empty，则不进行计算
            If IsEmpty(right) Then
                Goto continueInt
            End If

            ' 如果左值是 Empty，则不进行计算
            left = src.unsafeGetData(i)
            If IsEmpty(left) Then
                Goto continueInt
            End If

            src.unsafeSetData i, DateAdd("s", Int(-right), left)
continueInt:
        Next
    ElseIf desc.DataType = DF_DataType.DF_BOOLEAN Then
        For i = 0 To maxIndex
            right = desc.unsafeGetData(i)

            If IsEmpty(right) Then
                ' 如果右值是 Empty，则不进行计算
                Goto continueBoolean
            ElseIf right = False Then
                ' 如果右值是 False 时 + 0，即不做处理
                Goto continueBoolean
            End If

            ' 如果左值是 Empty，则不进行计算
            left = src.unsafeGetData(i)
            If IsEmpty(left) Then
                Goto continueInt
            End If

            src.unsafeSetData i, DateAdd("s", -1, left)
continueBoolean:
        Next
    End If
End Sub

' 该类型不支持这个计算
'
Public Sub IDFDataTypeHandler_mergeMultiply(ByRef src As IDFSeries, ByRef desc As IDFSeries)
End Sub

' 该类型不支持这个计算
'
Public Sub IDFDataTypeHandler_mergeDivide(ByRef src As IDFSeries, ByRef desc As IDFSeries)
End Sub

'----------------------------
' 聚合方法
'----------------------------
' 取全体数据的最大值
'
' @param data 数据集合
' @return 最大值
Public Function IDFDataTypeHandler_max(ByRef data As IDFSeries) As Variant
    Dim i As Long
    Dim result As Variant
    Dim temp As Variant

    ' 搜索第一个非 Empty 数据
    For i = 0 To data.Size - 1
        temp = data.unsafeGetData(i)
        If IsEmpty(temp) = False Then
            result = temp
            Exit For
        End If
    Next

    ' 开始比较大小
    For i = i To data.Size - 1
        temp = data.unsafeGetData(i)
        If IsEmpty(temp) = False Then
            If result < temp Then
                result = temp
            End If
        End If
    Next

    IDFDataTypeHandler_max = result
End Function

' 取全体数据的最小值
'
' @param data 数据集合
' @return 最小值
Public Function IDFDataTypeHandler_min(ByRef data As IDFSeries) As Variant
    Dim i As Long
    Dim result As Variant
    Dim temp As Variant

    ' 搜索第一个非 Empty 数据
    For i = 0 To data.Size - 1
        temp = data.unsafeGetData(i)
        If IsEmpty(temp) = False Then
            result = temp
            Exit For
        End If
    Next

    ' 开始比较大小
    For i = i To data.Size - 1
        temp = data.unsafeGetData(i)
        If IsEmpty(temp) = False Then
            If result > temp Then
                result = temp
            End If
        End If
    Next

    IDFDataTypeHandler_min = result
End Function

'================
' 数组引用聚合计算
'================
' 取全体数据的最大值
'
' @param data 数据数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @return 最大值
Public Function IDFDataTypeHandler_maxForArray(ByRef origin As Variant, ByRef size As Long) As Variant
    Dim i As Long
    Dim result As Variant
    Dim temp As Variant

    ' 搜索第一个非 Empty 数据
    For i = 0 To size - 1
        If IsEmpty(origin(i)) = False Then
            result = origin(i)
            Exit For
        End If
    Next

    ' 开始比较大小
    For i = i + 1 To size - 1
        temp = origin(i)
        If IsEmpty(temp) = False Then
            If result < temp Then
                result = temp
            End If
        End If
    Next

    IDFDataTypeHandler_maxForArray = result
End Function

' 取全体数据的最小值
'
' @param data 数据数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @return 最小值
Public Function IDFDataTypeHandler_minForArray(ByRef origin As Variant, ByRef size As Long) As Variant
    Dim i As Long
    Dim result As Variant
    Dim temp As Variant

    ' 搜索第一个非 Empty 数据
    For i = 0 To size - 1
        If IsEmpty(origin(i)) = False Then
            result = origin(i)
            Exit For
        End If
    Next

    ' 开始比较大小
    For i = i + 1 To size - 1
        temp = origin(i)
        If IsEmpty(temp) = False Then
            If result > temp Then
                result = temp
            End If
        End If
    Next

    IDFDataTypeHandler_minForArray = result
End Function


'----------------------------
' 比较运算
'----------------------------
'=========================================
' 对数组引用做比较，并生成 Boolean IDFSeries
'=========================================
' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' = 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_eqForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> True; Other ==> False
            result.appendData IsEmpty(origin(i))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            ' Empty <> Date ==> False
            result.appendData False
        Else
            ' Date_i = DateVal ==> True; Other ==> False
            result.appendData (origin(i) = realVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' != 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_neForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> False; Other ==> True
            result.appendData (Not IsEmpty(origin(i)))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            ' Empty <> Date ==> True
            result.appendData True
        Else
            ' Date_i = DateVal ==> False; Other ==> True
            result.appendData (origin(i) <> realVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' > 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_gtForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> False; 非Empty > Empty ==> True
            result.appendData (Not IsEmpty(origin(i)))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            ' Empty < Date ==> False
            result.appendData False
        Else
            ' Date_i > DateVal ==> True; Other ==> False
            result.appendData (origin(i) > realVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' < 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_ltForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> False; 非Empty > Empty ==> False
            result.appendData False
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            ' Empty < Date ==> True
            result.appendData True
        Else
            ' Date_i < DateVal ==> True; Other ==> False
            result.appendData (origin(i) < realVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' >= 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_geForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> True
            result.appendData True
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            ' Empty < Date ==> False
            result.appendData False
        Else
            ' Date_i >= DateVal ==> True; Other ==> False
            result.appendData (origin(i) >= realVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' <= 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_leForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> False
            result.appendData IsEmpty(origin(i))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            ' Empty < Date ==> True
            result.appendData True
        Else
            ' Date_i <= DateVal ==> True; Other ==> False
            result.appendData (origin(i) <= realVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' in() 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param vs 参与比较的数据数组
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_inValsForArray(ByRef origin As Variant, ByRef size As Long, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsForArray = innerSeries

    ' 2. 将所有 vs 转换成 Date 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        Else
            ' Date_i = DateVal ==> True; Other ==> False
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' between 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_betweenForArray(ByRef origin As Variant, ByRef size As Long, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Date 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenForArray = IDFDataTypeHandler_eqForArray(origin, size, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenForArray = innerSeries

    ' 2.2 left < right
    '     可能的情况:
    '      empty < Date
    '     不可能的情况:
    '      Date > empty
    Dim i As Long
    If IsEmpty(realLeft) Then
        ' empty < DateRight
        '  VVVVVV
        ' empty <= elem <= DateRight
        '  VVVVVV
        ' empty = Date_i(Empty) ==> True
        ' Date_i <= DateRight ==> True
        ' Other ==> False
        For i = 0 To size - 1
            If IsEmpty(origin(i)) Then
                result.appendData True
            Else
                result.appendData (origin(i) <= realRight)
            End If
        Next
    Else
        ' DateLeft <= elem <= DateRight
        ' Date_i(Empty) ==> False
        ' Other ==> Must Compare
        For i = 0 To size - 1
            If IsEmpty(origin(i)) Then
                result.appendData False
            Else
                result.appendData (origin(i) >= realLeft And origin(i) <= realRight)
            End If
        Next
    End If
End Function

'=========================================
' 对 Series 的数据做比较，并生成 Boolean IDFSeries
'=========================================
' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' = 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_eqForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; Other ==> False
            result.appendData IsEmpty(origin.unsafeGetData(i))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> False
            result.appendData False
        Else
            ' Date_i = DateVal ==> True; Other ==> False
            result.appendData (temp = realVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' != 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_neForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> False; Other ==> True
            result.appendData (Not IsEmpty(origin.unsafeGetData(i)))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> True
            result.appendData True
        Else
            ' Date_i = DateVal ==> False; Other ==> True
            result.appendData (temp <> realVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' > 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_gtForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> False; 非Empty > Empty ==> True
            result.appendData (Not IsEmpty(origin.unsafeGetData(i)))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            result.appendData False
        Else
            ' Date_i > DateVal ==> True; Other ==> False
            result.appendData (temp > realVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' < 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_ltForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> False; 非Empty > Empty ==> False
            result.appendData False
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            result.appendData True
        Else
            ' Date_i < DateVal ==> True; Other ==> False
            result.appendData (temp < realVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' >= 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_geForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> True
            result.appendData True
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            result.appendData False
        Else
            ' Date_i >= DateVal ==> True; Other ==> False
            result.appendData (temp >= realVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' <= 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_leForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> False
            result.appendData IsEmpty(origin.unsafeGetData(i))
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            result.appendData True
        Else
            ' Date_i <= DateVal ==> True; Other ==> False
            result.appendData (temp <= realVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' in() 运算
'
' @param origin 需要比较的 Series
' @param vs 参与比较的数据数组
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_inValsForSeries(ByRef origin As IDFSeries, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsForSeries = innerSeries

    ' 2. 将所有 vs 转换成 Date 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        Else
            ' Date_i = DateVal ==> True; Other ==> False
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' between 运算
'
' @param origin 需要比较的 Series
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_betweenForSeries(ByRef origin As IDFSeries, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Date 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenForSeries = IDFDataTypeHandler_eqForSeries(origin, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenForSeries = innerSeries

    ' 2.2 left < right
    '     可能的情况:
    '      empty < Date
    '     不可能的情况:
    '      Date > empty
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        ' empty < DateRight
        '  VVVVVV
        ' empty <= elem <= DateRight
        '  VVVVVV
        ' empty = Date_i(Empty) ==> True
        ' Date_i <= DateRight ==> True
        ' Other ==> False
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If IsEmpty(temp) Then
                result.appendData True
            Else
                result.appendData (temp <= realRight)
            End If
        Next
    Else
        ' DateLeft <= elem <= DateRight
        ' Date_i(Empty) ==> False
        ' Other ==> Must Compare
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If IsEmpty(temp) Then
                result.appendData False
            Else
                result.appendData (temp >= realLeft And temp <= realRight)
            End If
        Next
    End If
End Function

'=========================================
' 对数组引用做比较，并生成 IDFSeries 来保存比较结果为 true 的 数据
'=========================================
' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' = 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_eqToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqToSeriesForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> True; Other ==> False
            If IsEmpty(origin(i)) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> False
            ' noop
        ElseIf temp = realVal Then
            ' Date_i = DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' != 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_neToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neToSeriesForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            temp = origin(i)
            ' Empty = Empty ==> False; Other ==> True
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> True
            result.appendEmpty
        ElseIf temp <> realVal Then
            ' Date_i = DateVal ==> False; Other ==> True
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' > 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_gtToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtToSeriesForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            temp = origin(i)
            ' Empty = Empty ==> False; 非Empty > Empty ==> True
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            ' noop
        ElseIf temp > realVal Then
            ' Date_i > DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' < 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_ltToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltToSeriesForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        ' Empty = Empty ==> False; 非Empty > Empty ==> False
        ' 全部数据不符合规则，返回空数据对象

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            result.appendEmpty
        ElseIf temp < realVal Then
            ' Date_i < DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' >= 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_geToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geToSeriesForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> True
            result.appendData origin(i)
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            ' noop
        ElseIf temp >= realVal Then
            ' Date_i >= DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' <= 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_leToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leToSeriesForArray = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> False
            If IsEmpty(origin(i)) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            result.appendEmpty
        ElseIf temp <= realVal Then
            ' Date_i <= DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' in() 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param vs 参与比较的数据数组
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_inValsToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsToSeriesForArray = innerSeries

    ' 2. 将所有 vs 转换成 Date 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendEmpty
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则忽略
        Else
            ' Date_i = DateVal ==> True; Other ==> False
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData temp
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则忽略
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' between 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_betweenToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Date 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenToSeriesForArray = IDFDataTypeHandler_eqToSeriesForArray(origin, size, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenToSeriesForArray = innerSeries

    ' 2.2 left < right
    '     可能的情况:
    '      empty < Date
    '     不可能的情况:
    '      Date > empty
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        ' empty < DateRight
        '  VVVVVV
        ' empty <= elem <= DateRight
        '  VVVVVV
        ' empty = Date_i(Empty) ==> True
        ' Date_i <= DateRight ==> True
        ' Other ==> False
        For i = 0 To size - 1
            temp = origin(i)
            If IsEmpty(temp) Then
                result.appendEmpty
            ElseIf temp <= realRight Then
                result.appendData temp
            End If
        Next
    Else
        ' DateLeft <= elem <= DateRight
        ' Date_i(Empty) ==> False
        ' Other ==> Must Compare
        For i = 0 To size - 1
            temp = origin(i)
            If IsEmpty(temp) Then
                ' noop
            ElseIf temp >= realLeft And temp <= realRight Then
                result.appendData temp
            End If
        Next
    End If
End Function

'=========================================
' 对 Series 的数据做比较，并生成 IDFSeries 来保存结果为 true 的 数据
'=========================================
' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' = 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_eqToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqToSeriesForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; Other ==> False
            If IsEmpty(origin.unsafeGetData(i)) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> False
            ' noop
        ElseIf temp = realVal Then
            ' Date_i = DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' != 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_neToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neToSeriesForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            ' Empty = Empty ==> False; Other ==> True
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> True
            result.appendEmpty
        ElseIf temp <> realVal Then
            ' Date_i = DateVal ==> False; Other ==> True
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' > 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_gtToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtToSeriesForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            ' Empty = Empty ==> False; 非Empty > Empty ==> True
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            ' noop
        ElseIf temp > realVal Then
            ' Date_i > DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' < 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_ltToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltToSeriesForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        ' Empty = Empty ==> False; 非Empty > Empty ==> False
        ' 全部数据不符合规则，返回空数据对象

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            result.appendEmpty
        ElseIf temp < realVal Then
            ' Date_i < DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' >= 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_geToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geToSeriesForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> True
            result.appendData origin.unsafeGetData(i)
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            ' noop
        ElseIf temp >= realVal Then
            ' Date_i >= DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' <= 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_leToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leToSeriesForSeries = innerSeries

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> False
            If IsEmpty(origin.unsafeGetData(i)) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            result.appendEmpty
        ElseIf temp <= realVal Then
            ' Date_i <= DateVal ==> True; Other ==> False
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' in() 运算
'
' @param origin 需要比较的 Series
' @param vs 参与比较的数据数组
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_inValsToSeriesForSeries(ByRef origin As IDFSeries, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsToSeriesForSeries = innerSeries

    ' 2. 将所有 vs 转换成 Date 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendEmpty
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则忽略
        Else
            ' Date_i = DateVal ==> True; Other ==> False
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData temp
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则忽略
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' between 运算
'
' @param origin 需要比较的 Series
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_betweenToSeriesForSeries(ByRef origin As IDFSeries, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Date 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenToSeriesForSeries = IDFDataTypeHandler_eqToSeriesForSeries(origin, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=fieldDataType
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenToSeriesForSeries = innerSeries

    ' 2.2 left < right
    '     可能的情况:
    '      empty < Date
    '     不可能的情况:
    '      Date > empty
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        ' empty < DateRight
        '  VVVVVV
        ' empty <= elem <= DateRight
        '  VVVVVV
        ' empty = Date_i(Empty) ==> True
        ' Date_i <= DateRight ==> True
        ' Other ==> False
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If IsEmpty(temp) Then
                result.appendEmpty
            ElseIf temp <= realRight Then
                result.appendData temp
            End If
        Next
    Else
        ' DateLeft <= elem <= DateRight
        ' Date_i(Empty) ==> False
        ' Other ==> Must Compare
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If IsEmpty(temp) Then
                ' noop
            ElseIf temp >= realLeft And temp <= realRight Then
                result.appendData temp
            End If
        Next
    End If
End Function

'=========================================
' 对 Series 的数据做比较，并生成包含结果为 true 的数据切片 Series
'=========================================
' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' = 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_eqToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_eqToSliceForSeries = dfSlice

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; Other ==> False
            If IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> False
            ' noop
        ElseIf temp = realVal Then
            ' Date_i = DateVal ==> True; Other ==> False
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' != 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_neToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_neToSliceForSeries = dfSlice

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> False; Other ==> True
            If Not IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty <> Date ==> True
            dfSlice.appendRef i
        ElseIf temp <> realVal Then
            ' Date_i = DateVal ==> False; Other ==> True
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' > 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_gtToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_gtToSliceForSeries = dfSlice

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> False; 非Empty > Empty ==> True
            If Not IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            ' noop
        ElseIf temp > realVal Then
            ' Date_i > DateVal ==> True; Other ==> False
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' < 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_ltToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_ltToSliceForSeries = dfSlice

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        ' Empty = Empty ==> False; 非Empty > Empty ==> False
        ' 全部数据不符合规则，返回空数据对象

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            dfSlice.appendRef i
        ElseIf temp < realVal Then
            ' Date_i < DateVal ==> True; Other ==> False
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' >= 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_geToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    Set IDFDataTypeHandler_geToSliceForSeries = dfSlice

    ' 2. 将 v 转换成 Time 或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        ' 需要获取全部引用
        ' Empty = Empty ==> True; 非Empty > Empty ==> True
        dfSlice.Init origin

        Exit Function
    End If

    ' 4. 初始化结果对象
    dfSlice.InitEmptyRef origin

    ' 5. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> False
            ' noop
        ElseIf temp >= realVal Then
            ' Date_i >= DateVal ==> True; Other ==> False
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' <= 运算
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_leToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_leToSliceForSeries = dfSlice

    ' 2. 将 v 转换成日期数据或 Empty
    Dim realVal As Variant
    realVal = IDFDataTypeHandler_normalize(v)

    ' 3. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(realVal) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty ==> True; 非Empty > Empty ==> False
            If IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 4. 对各数据进行比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty < Date ==> True
            dfSlice.appendRef i
        ElseIf temp <= realVal Then
            ' Date_i <= DateVal ==> True; Other ==> False
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' in() 运算
'
' @param origin 需要比较的 Series
' @param vs 参与比较的数据数组
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_inValsToSliceForSeries(ByRef origin As IDFSeries, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_inValsToSliceForSeries = dfSlice

    ' 2. 将所有 vs 转换成 Date 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    dfSlice.appendRef i
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则忽略
        Else
            ' Date_i = DateVal ==> True; Other ==> False
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    dfSlice.appendRef i
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则忽略
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' between 运算
'
' @param origin 需要比较的 Series
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_betweenToSliceForSeries(ByRef origin As IDFSeries, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Date 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenToSliceForSeries = IDFDataTypeHandler_eqToSliceForSeries(origin, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_betweenToSliceForSeries = dfSlice

    ' 2.2 left < right
    '     可能的情况:
    '      empty < Date
    '     不可能的情况:
    '      Date > empty
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        ' empty < DateRight
        '  VVVVVV
        ' empty <= elem <= DateRight
        '  VVVVVV
        ' empty = Date_i(Empty) ==> True
        ' Date_i <= DateRight ==> True
        ' Other ==> False
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If IsEmpty(temp) Then
                dfSlice.appendRef i
            ElseIf temp <= realRight Then
                dfSlice.appendRef i
            End If
        Next
    Else
        ' DateLeft <= elem <= DateRight
        ' Date_i(Empty) ==> False
        ' Other ==> Must Compare
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If IsEmpty(temp) Then
                ' noop
            ElseIf temp >= realLeft And temp <= realRight Then
                dfSlice.appendRef i
            End If
        Next
    End If
End Function